<?php 

require_once 'domain/UserPreferencias.php';
require_once(APPPATH.'libraries/MY_Model.php');

class M_user_preferencias extends MY_Model {

	function M_user_preferencias()
	{
		parent::MY_Model('user_preferencias','pref_id');
	}

	/*****************************************************
	 * GENERAL
	 ****************************************************/

	protected function afromEntityToDb(UserPreferencias $param){
		return array(
			'pref_id'	=> $param->id,
			'user_id'	=> $param->user_id,
			'pref_name'	=> $param->name,
			'pref_value'=> $param->value,
		);
	}

	protected function  afromDbToEntity(array $p_param) {
		$p = new UserPreferencias();
		$p->id		= $p_param['pref_id'];
		$p->user_id	= $p_param['user_id'];
		$p->name	= $p_param['pref_name'];
		$p->value	= $p_param['pref_value'];
		return $p;
	}

	/*****************************************************
	 * ACCESO A DATOS
	 ****************************************************/

	function getPref($userid,$pref_name){
		$this->db->where(array('user_id'=>$userid,"pref_name"=>$pref_name));
		$query = $this->db->get($this->TABLE_NAME,1);
		return $this->fromDbToEntity($query->result_array());
	}

}

?>
